﻿# -- Persist_m.py
"""
    Copyright 2013 J. Kent Harbaugh

    This file is part of Raddel.

    Raddel is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Raddel is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Raddel.  If not, see <http://www.gnu.org/licenses/>.
"""



class Persist_t:
    def Load(Self,Label):
        filename=Self.makeFilename(Label)
        try:
            file=bz2.BZ2File(filename,mode='r')
            try:
                obj=pickle.load(file)
            except OSError:
                obj=None
            file.close()
        except OSError:
            obj=None
        return obj
    def Save(Self,Label,Obj):
        filename=Self.makeFilename(Label)
        file=bz2.BZ2File(filename,mode='w')
        pickle.dump(Obj,file)
        file.close()
    def __init__(Self,Folder):
        Self._Folder=Folder
        os.makedirs(Self._Folder,exist_ok=True)
    def makeFilename(Self,Label):
        return Self._Folder+'\\'+Label+'.pickle.bz2'



import bz2, os, pickle



# -- Persist_m.py
